home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / tools / to_jfif.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-11  |  1.8 KB  |  82 lines

  1. /*
  2.  * Copyright (c) 1992    Jin Guojun
  3.  *
  4.  * Disclaimer:  No guarantees of performance accompany this software,
  5.  * nor is any responsibility assumed on the part of the authors.  All the
  6.  * software has been tested extensively and every effort has been made to
  7.  * insure its reliability.
  8.  *
  9.  * to_hjpeg - convert an image to HIPS-JPEG format
  10.  *
  11.  * usage:    to_hjpeg < idata > oseq
  12.  *
  13.  * to load:    cc -o to_jfif to_jfif.c -lhips
  14.  *
  15.  * AUTHOR:    Jin Guojun - 11/12/92
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include <hipl_format.h>
  20.  
  21. static Flag_Format flagfmt[] =
  22. {
  23.     {"o", {LASTFLAG}, 0, {{PTBOOLEAN, "FALSE"}, LASTPARAMETER}},
  24.     LASTFLAG};
  25.  
  26. #define    M_EOI    0xD9
  27. #define    M_SOS    0xDA
  28.  
  29.  
  30. main(argc, argv)
  31.     int       argc;
  32.     char    **argv;
  33.  
  34. {
  35.     int       oform;
  36.     Boolean   oflag;
  37.     int       rows, cols, frames, f, numcolor, pad, ch1;
  38.     int       xstream[2], xjpeg[2];
  39.     struct header hd;
  40.     sframe_header fhd;
  41.     Filename  filename;
  42.     FILE     *fp;
  43.  
  44.     Progname = strsave(*argv);
  45.     parseargs(argc, argv, flagfmt, &oflag, FFONE, &filename);
  46.  
  47.     fp = hfopenr(filename);
  48.     fread_header(fp, &hd, filename);
  49.     alloc_image(&hd);
  50.  
  51.  
  52.     while(1) {
  53.         ch1 = fgetc(fp);
  54.         fputc(ch1,stdout);
  55.     if (ch1 == 0xff)    {
  56.         ch1 = fgetc(fp);
  57.         fputc(ch1,stdout);
  58.         if (ch1 == M_SOS)    break;
  59.     }
  60.     }
  61.     fgetc(fp);
  62.     fputc(0, stdout);
  63.     ch1 = fgetc(fp);
  64.     fputc(ch1, stdout);
  65.     fprintf(stderr, "jfif size %d \n", (int)ch1);
  66.     ch1-=2;
  67.     while (ch1--)    fputc(fgetc(fp) , stdout);
  68.  
  69.     fread(&fhd, sizeof(sframe_header), 1, fp);
  70.     fprintf(stderr, "frame %d, size %d \n", fhd.frame, fhd.size);
  71.  
  72.     /* this will do 1st frame only */
  73.     if (fread(hd.image, fhd.size, 1, fp) != 1)
  74.         return (perr(HE_READFRFILE, f, filename));
  75.     if (fwrite(hd.image, fhd.size, 1, stdout) != 1)
  76.         return (perr(HE_READFRFILE, f, filename));
  77.  
  78.     write_jpeg_eof(stdout);
  79.     fclose(stdout);
  80.     return (0);
  81. }
  82.